<?php echo $this->render('layouts/__header.phtml'); ?>
<?php echo $this->render('layouts/__nav.phtml'); ?>

<link rel="stylesheet" type="text/css" href="/css/task.css" />

		<h1>Ticket List</h1>
		<div id="tasklistbox">
	    <table class="normaltable">
			<tr class="selectarea">
					<td></td>
					<td></td>
					<td><?php echo $this->formSelect('status', $this->filter['status'], null, $this->entites['status']) ?></td>
					<td><?php echo $this->formSelect('property_id', $this->filter['property_id'], null, $this->entites['property']) ?></td>
					<td class="title"><input id="title" name="title" type="text" class="title" value="<?php echo $this->filter['title']?>" /></td>
					<td><?php echo $this->formSelect('requester_id', $this->filter['requester_id'], null, $this->entites['requester']) ?></td>
					<td><?php echo $this->formSelect('replier_id', $this->filter['replier_id'], null, $this->entites['manager']) ?></td>
					<td></td>
					<td></td>
					<td class="sub"></td>
			</tr>		
			<tr class="tit">
					<td>ID</td>
					<td class="attachment"><img src="/images/icon_attach.gif"/></td>
					<td>Status</td>
					<td>Property</td>
					<td class="title">Title</td>
					<td>Requester</td>
					<td>Replier</td>
					<td>Roadmap</td>
					<td>Edit</td>
					<td>Reply</td>
			</tr>
			<?php if (!sizeof($this->ticket_list)): ?>
				<tr><td colspan="13" style="color:#cc0000;height:50px;"><b>Empty Ticket List ...</b></td></tr>
			<?php else: ?>
				<?php foreach ($this->ticket_list as $ticket): ?>
				<tr id="ticket_<?php echo $ticket['id']?>" style="background:#fff" onMouseOver="this.style.backgroundColor='#F7F9F9';" onMouseOut="this.style.backgroundColor='#fff'">
				<td><?php echo $ticket['id']?></td>
				<td><?php echo $ticket['attach']?></td>
				<td><?php echo $ticket['status']?></td>
				<td><?php echo $ticket['property']?></td>
				<td class="title"><?php echo $ticket['title']?></td>
				<td><?php echo $ticket['requester']?></td>
				<td><?php echo $ticket['replier']?></td>
				<td><?php echo $ticket['roadmap']?></td>
				<td><input type="button" value="Edit" <?php echo $ticket['onEdit']?>/></td>
				<td><input type="button" value="Reply" <?php echo $ticket['onReply']?>/></td>
				</tr>
				<?php endforeach; ?>
			<?php endif; ?>
		</table>
		</div>
		
		<div class="listbottom">
			<div class="pagelist" <?php if (!$this->pager) {echo 'style="display:none"';} ?> ><?php echo $this->pager['prevStr'];?>&nbsp;<?php echo $this->pager['pageStr'];?>&nbsp;<?php echo $this->pager['nextStr'];?>&nbsp;<input id="pageto" type="text" /><a id="gopagebtn" href="javascript:;">Go</a></div>
			<input id="addtaskbtn" type="button" value="Add New Ticket" />
		</div>

		<div id="loadingbox" style="display:none;padding:2px 0px 0px 8px;width:125px;height:20px;text-align:center;position:absolute;top:0px;right:0px;background:#CC0000;color:#fff"><b>Loading ...</b></div>

<script type="text/javascript" src="/js/mootools.js"></script>
<script type="text/javascript" src="/js/base.js"></script>
<script type="text/javascript">
window.addEvent('domready', function(){
	$('gopagebtn').addEvent('click', function(e){
		e = new Event(e);
		var page_to = parseInt($('pageto').value);
		var page_num = (page_to > 1) ? $('pageto').value : 1;
		var page_url = '<?php echo $this->base_url;?>index/p/'+page_num;
		redirect(page_url);
		e.stop();
		
	});
	$('addtaskbtn').addEvent('click', function(e){
		e = new Event(e);
		redirect('<?php echo $this->create_url;?>');
		e.stop();
	});
	/////////////////////////////////////////////////////
	// search select from
	var request_uri = '<?php echo $this->filter_url;?>?t='+(new Date()).getTime();
	['status','property_id','requester_id','replier_id'].each(function(item, index){
		$(item).addEvent('change', function(e){
			$('loadingbox').setStyle('display', 'block');
			new Ajax(request_uri, {
				method: 'get',
				data: Object.toQueryString({
					k: item,
					v: $(item).value
				}),
				onComplete: function(){
					if ('success' == this.response.text) {
						redirect('<?php echo $this->base_url;?>');
					}
				}
			}).request();
		});
	});
	['title'].each(function(item, index){
		$(item).addEvent('keyup', function(e){
			var event = new Event(e);
			if (event.key == 'enter') {
				$('loadingbox').setStyle('display', 'block');
				new Ajax(request_uri, {
					method: 'get',
					data: Object.toQueryString({
						k: item,
						v: $(item).value
					}),
					onComplete: function(){
						if ('success' == this.response.text) {
							redirect('<?php echo $this->base_url;?>');
						}
					}
				}).request();
			}
			event.stop();
		});
	});
});
</script>

<?php echo $this->render('layouts/__footer.phtml'); ?>